package com.xinzhi.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class User implements UserDetails {
    //id
    private Integer id;
    //名字
    private String username;
    //密码
    private String password;
    //邮箱
    private String email;
    //手机号
    private String phonenumber;
    //地址
    private String address;
    //用户uid
    private Integer uid;
    //用户种类
    private String usertype;
    //暂时存储的验证码(用户输入的验证码)
    private String message;
    //忘记密码时的第一个密码
    private String onepassword;
    //忘记密码时的第二个密码
    private String twopassword;
    //用户角色列表
    private List<String> role;
    //用户的权限集合
    private Collection<? extends GrantedAuthority> authorities;
    //是否没过期
    private boolean accountNonExpired;
    //是否没被锁定
    private boolean accountNonLocked;
    //密码是否没过期
    private boolean credentialsNonExpired;
    //账号是否可用
    private boolean enabled;
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }
    public List<String> getRole() {
        return role;
    }


    @Override
    public boolean isAccountNonExpired() {
        return true;   //暂时未用到，直接返回true，表示账户未过期
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;   //暂时未用到，直接返回true，表示账户未被锁定
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;   //暂时未用到，直接返回true，表示账户密码未过期
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
